package com.foreknow.demo5;

import com.foreknow.demo2.Dog;
import com.foreknow.demo2.Pet;

import java.awt.*;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

/**
 * 方法的参数与返回值类型：接口类型
 */
public class MethodDemo {

    /**
     * m1方法
     * @param a 父类型(接口类型) 体现Java中的多态
     */
    public void m1(A a) {
        a.method_A();
    }

    public A m2() {
        A a = new AImpl();
        return a;
    }

    public void m3(Pet pet) {
        pet.toHospital();
    }

    public Pet m4() {
        Pet dog = new Dog();
        return dog;
    }

    public void m5(ActionListener actionListener) {
        actionListener.actionPerformed(null);
    }

    public ActionListener m6() {
        ActionListener actionListener = new ActionListenerImpl();
        return actionListener;
    }

    public void m7(List list) {
        list.size();
    }

    public List m8() {
        return new ArrayList();
    }

    public static void main(String[] args) {
        MethodDemo methodDemo = new MethodDemo();
        A a = new AImpl();
        methodDemo.m1(a);

        A aa = methodDemo.m2();
        aa.method_A();

        Pet pet = new Dog();
        methodDemo.m3(pet);

        Pet pp = methodDemo.m4();
        pp.toHospital();
    }
}
